package com.giantlizard.cloud.base.enums;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum HttpStatusCodeEnum {
    SUCCESS(200, "操作成功"),
    DATA_EXIST(300, "数据已存在，请核实"),
    MOVED_PERMANENTLY(301, "永久移动"),
    FOUND(302, "临时移动"),
    SEE_OTHER(303, "查看其他"),
    NOT_MODIFIED(304, "未修改"),
    TEMPORARY_REDIRECT(307, "临时重定向"),
    PERMANENT_REDIRECT(308, "永久重定向"),
    BAD_REQUEST(400, "参数错误，请检查参数是否正确"),
    NOT_AUTHENTICATION(401, "认证失败，token非法"),
    TOKEN_INVALID(402, "认证失败，请检查token是否过期"),
    DATA_INVALID(402, "数据校验失败"),
    UNAUTHORIZED(403, "尚未配置该操作权限，请联系管理员"),
    NOT_FOUND(404, "资源不存在"),
    USER_NOT_FOUND(404, "用户不存在"),
    NOT_SUPPORT_METHOD(405, "不支持的请求方法"),
    NOT_SUPPORT_MEDIA_TYPE(415, "不支持当前媒体类型"),
    INTERNAL_ERROR(500, "系统内部错误，请联系技术人员"),
    NOT_DELETE(406, "当前数据不支持删除！"),
    NOT_UPDATE(407, "当前数据不支持修改！"),
    NOT_INSERT(408, "不允许添加该数据状态，请核实"),
    // 服务器错误响应
    INTERNAL_SERVER_ERROR(500, "系统内部错误，请联系技术人员"),
    NOT_IMPLEMENTED(501, "请求方法未实现"),
    BAD_GATEWAY(502, "网关错误"),
    SERVICE_UNAVAILABLE(503, "服务不可用"),
    GATEWAY_TIMEOUT(504, "网关超时"),
    HTTP_VERSION_NOT_SUPPORTED(505, "不支持的HTTP版本"),
    VARIANT_ALSO_NEGOTIATES(506, "变体也协商"),
    INSUFFICIENT_STORAGE(507, "存储不足"),
    LOOP_DETECTED(508, "检测到循环"),
    NOT_EXTENDED(510, "未扩展"),
    NETWORK_AUTHENTICATION_REQUIRED(511, "网络认证所需");



    private final int code;
    private final String msg;

    public static String getMsgByCode(int code) {
        for (HttpStatusCodeEnum statusCodeEnum : HttpStatusCodeEnum.values()) {
            if (statusCodeEnum.getCode() == code) {
                return statusCodeEnum.getMsg();
            }
        }
        return null;
    }

    public static int getCodeByMsg(String msg) {
        for (HttpStatusCodeEnum statusCodeEnum : HttpStatusCodeEnum.values()) {
            if (statusCodeEnum.getMsg().equals(msg)) {
                return statusCodeEnum.getCode();
            }
        }
        return 0;
    }

}
